package com.dqp.cslggroup.JWXT;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dqp.cslggroup.UI.MyApplication;
import com.dqp.cslggroup.Util.SharedPreferencesUtil;
import com.dqp.cslggroup.bean.student;

import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.Map;


public class GetStudentInformaction {
    private String getinformaction_url;
    private Connection.Response response;
    private String stuNum;
    private Map<String, String> getinformaction_cookies;
    private String Authorization = SharedPreferencesUtil.getStringSp(MyApplication.getContext(), "Authorization", "");


    public GetStudentInformaction(String url, String stuid, Map<String, String> cookies) {
        this.getinformaction_url = url;
        this.stuNum = stuid;
        this.getinformaction_cookies = cookies;
    }


    student getinformaction() throws IOException {
        response = Jsoup.connect(getinformaction_url + "/jwglxt/xsxxxggl/xsxxwh_cxCkDgxsxx.html?gnmkdm=N100801&su=" + stuNum)
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
                .cookies(getinformaction_cookies)
                .header("Authorization", Authorization)
                .timeout(5000)
                .ignoreContentType(true)
                .execute();
        if (response.body() != null && response.body().contains("{")) {
            JSONObject jsonObject = JSON.parseObject(response.body());
            student student = new student();
            if (!jsonObject.getString("xh_id").isEmpty()) {
                student.setXh(jsonObject.getString("xh_id"));
                student.setXm(jsonObject.getString("xm"));
                student.setXb(jsonObject.getString("xbm"));
                student.setSr(jsonObject.getString("csrq"));
                student.setSyd(jsonObject.getString("syd"));
                student.setXy(jsonObject.getString("jg_id"));
                student.setBj(jsonObject.getString("bh_id"));
                student.setZy(jsonObject.getString("zyh_id"));
                student.setSf(jsonObject.getString("pyfsdm"));
                student.setRxnf(jsonObject.getString("njdm_id"));
                student.setZzmm(jsonObject.getString("zzmmm"));
            }
            return student;
        }
        return null;
    }


}
